package com.baizhi.service.impl;

import com.baizhi.dao.GuruDao;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lenovo on 2019/6/17.
 */
@Service
@Transactional
public class GuruServiceImpl implements GuruService {

    @Autowired
    private GuruDao guruDao;




    //分页查询上师
    @Override
    public Map fenye(int page, int rows, String guruName) {
        if(guruName!=null&&!"".equals(guruName)){
            guruName="%"+guruName+"%";
        }else {
            guruName=null;
        }
        Map map=new HashMap();
        int total = guruDao.total(guruName);
        map.put("total",total);
        int start=(page-1)*rows;
        int pageSize=page*rows;
        List<Guru> list = guruDao.fenye(start,pageSize,guruName);
        map.put("rows" ,list);
        return map;
    }


    //添加上师的接口
    @Override
    public void add(Guru guru) {
        guruDao.add(guru);
    }

    //修改上师
    @Override
    public void update(Guru guru) {
        guruDao.update(guru);
    }

    //删除上师
    @Override
    public void delete(int[] ids) {
        guruDao.delete(ids);
    }

    //查询所有的上师(导出用)
    @Override
    public List<Guru> selectAll() {
        return guruDao.selectAll();
    }


}
